{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 高斯滤波\n",
    "import cv2\n",
    "import numpy as np\n",
    "img = cv2.imread('image11.jpg',1)\n",
    "cv2.imshow('img',img)\n",
    "dstImg = cv2.GaussianBlur(img,(5,5),1.5)\n",
    "cv2.imshow('dst',dstImg)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 均值滤波：定义6*6的全1矩阵然后做卷运算求均值，之后再用均值代替区域内的中心像素\n",
    "img = cv2.imread('image11.jpg',1)\n",
    "imgInfo = img.shape\n",
    "height = imgInfo[0]\n",
    "width = imgInfo[1]\n",
    "dstImg = np.zeros((height,width,3),np.uint8)\n",
    "for i in range(3,height-3):\n",
    "    for j in range(3,width-3):\n",
    "        sum_b = int(0)\n",
    "        sum_g = int(0)\n",
    "        sum_r = int(0)\n",
    "        for m in range(-3,3):\n",
    "            for n in range(-3,3):\n",
    "                (b,g,r) = img[i+m,j+n]\n",
    "                sum_b = sum_b+int(b)\n",
    "                sum_g = sum_g+int(g)\n",
    "                sum_r = sum_r+int(r)\n",
    "        b = np.uint8(sum_b/36)\n",
    "        g = np.uint8(sum_g/36)\n",
    "        r = np.uint8(sum_r/36)\n",
    "        dstImg[i,j]=(b,g,r)\n",
    "cv2.imshow('dst',dstImg)\n",
    "cv2.waitKey(0)       "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
